﻿#pragma once
#include "yzrutil.h"
#include "OutputStream.h"
#include "array/Array.hpp"
#include "lang/String.h"

namespace yzrilyzr_io{
	ECLASS(ByteArrayOutputStream, public OutputStream){
	protected:
	yzrilyzr_array::ByteArray buf;
	u_index count=0;
	private:
	void ensureCapacity(u_index minCapacity);
	public:
	ByteArrayOutputStream();
	ByteArrayOutputStream(u_index size);
	~ByteArrayOutputStream();
	void write(int32_t b)override;
	using OutputStream::write;
	void write(const yzrilyzr_array::ByteArray & b, u_index off, u_index len)override;
	void writeBytes(const yzrilyzr_array::ByteArray & b);
	void writeTo(OutputStream & out);
	void reset();
	yzrilyzr_array::ByteArray toByteArray()const;
	u_index size()const;
	yzrilyzr_lang::String toString()const override;
	yzrilyzr_lang::String toString(yzrilyzr_lang::StringEncoding encoding)const;
	void close()override;
	};
}